# -*- encoding=utf8 -*-
"""
RedFlag-TC0000105  （拍摄进入装饰页）文字长度功能
输入文案场景
删除输入的文案场景
新增文字点击保存场景
新增文字点击空白处场景
新增保存带颜色气泡的文字场景
"""
__author__ = "ldm"

import sys
import os

# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
from device_elements import *

auto_setup(__file__)
shooter = CameraVideoShooter()

log("--------------------------------输入文案场景--------------------------------------")
"""
拍摄视频进入装饰页
点击文字
获取文本
输入文案
获取文本
断言
"""

shooter.enter_photography_decoration_page()
shooter.click_element(decoration_page_text_function)
text1 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/text_edit_et"))
shooter.random_input_chars(decoration_page_text_function_input, 50)
sleep(1.0)
text2 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/text_edit_et"))
shooter.assert_texts_not_equal(text1, text2, "断言失败，比对值一致，并未新增文字")

log("--------------------------------清除文案场景--------------------------------------")
"""
点击清除按钮
获取文本
断言
"""

shooter.click_element(decoration_page_text_function_delete)
text3 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/text_edit_et"))
shooter.assert_texts_equal(text1, text3, "断言失败，比对值不一致，说明清楚按钮失效")

log("--------------------------------新增文字点击保存场景--------------------------------------")
"""
新增文案
选择一个字体“启黑体”
点击颜色
选择第一个颜色
点击气泡
选择第一个气泡
点击确定
点击屏幕
断言
"""

shooter.random_input_chars(decoration_page_text_function_input, 50)
shooter.click_element(decoration_page_text_function_font[4])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[1])
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[1])
shooter.click_element(decoration_page_text_function_confirm)
touch((0.5,0.5))
shooter.assert_element_exists(decoration_page_text_editing,"断言失败，预期元素并未出现")
shooter.click_element(decoration_page_text_editing_delete)

log("--------------------------------新增文字点击空白处保存场景--------------------------------------")
"""
新增文案
选择一个字体“启黑体”
点击颜色
选择第一个颜色
点击气泡
选择第一个气泡
点击确定
点击屏幕
断言
"""

shooter.click_element(decoration_page_text_function)
shooter.random_input_chars(decoration_page_text_function_input, 25)
shooter.click_element(decoration_page_text_function_font[5])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[2])
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[2])
touch((0.45,0.5))
sleep(1.0)
touch((0.5,0.5))
shooter.assert_element_exists(poco("cn.migu.video.clip.walle:id/container"),"断言失败，预期元素并未出现")


log("--------------------------------新增保存带颜色气泡的文字场景--------------------------------------")

shooter.click_element(decoration_page_text_editing)
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[3])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[2])
shooter.click_element(decoration_page_text_function_confirm)
shooter.click_element(decoration_page_save)
shooter.wait_for_element_disappearance(decoration_page_save_animation, 120)
shooter.click_element(set_video_ringtone)
shooter.wait_for_element_appearance(set_video_ringtone_play, 30)
shooter.click_element(set_video_ringtone_play)
photo1 = shooter.capture_screenshot("TC0000105A.png")

# 关闭应用
stop_app(UGC_package_name)

# 获取手机品牌
phone_model = shooter.get_phone_model()


# ---------------------------------华为P50----------------------------------
if phone_model:
    if "huawei" in phone_model.lower() or "华为" in phone_model:
        shooter.click_element(Comes_photo_album_huawei)
        shooter.click_element(Comes_photo_album_all_photos[1].child("com.huawei.photos:id/album_cover_image"))
        shooter.click_element(Comes_photo_album_select[0])
        touch((0.5,0.2))
        sleep(2.0)
        photo2 = shooter.capture_screenshot("TC0000105B.png")
        shooter.assert_images_equal(photo1, photo2, "断言失败，图片比对不成功")
        stop_app("com.huawei.photos")
    elif "vivo" in phone_model.lower():
        shooter.click_element(Comes_photo_album_vivo)
        shooter.click_element(Comes_photo_album_all_photos_vivo)
        shooter.click_element(Comes_photo_album_frist_video_vivo.child())
        touch((0.5, 0.2))
        sleep(2.0)
        photo2 = shooter.capture_screenshot("TC0000105B.png")
        shooter.assert_images_equal(photo1, photo2, "断言失败，图片比对不成功")
        stop_app("com.vivo.gallery")
    else:
        print(f"不支持的手机品牌: {phone_model}")
else:
    print("无法获取手机型号信息，跳过断言操作")